package model.enums;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * zzx
 */
public enum ChildTypeEnum {

    ORDER(10, "订单提醒",MessageTypeEnum.ORDER.name()),
    ORDER2(20, "订单提醒2",MessageTypeEnum.ORDER.name()),

    REFUND(30, "退款提醒",MessageTypeEnum.REFUND.name()),
    REFUND2(40, "退款提醒2",MessageTypeEnum.REFUND.name()),

    AFTERSALE(50, "售后提醒",MessageTypeEnum.AFTERSALE.name()),
    AFTERSALE2(60, "售后提醒2",MessageTypeEnum.AFTERSALE.name()),

    COUPON(70, "优惠券提醒",MessageTypeEnum.COUPON.name()),
    COUPON2(80, "优惠券提醒2",MessageTypeEnum.COUPON.name()),

    ACTIVITY(90, "活动通知",MessageTypeEnum.ACTIVITY.name()),
    ACTIVITY2(100, "活动通知2",MessageTypeEnum.ACTIVITY.name()),

    COMMENT(110, "评论通知",MessageTypeEnum.COMMENT.name()),
    COMMENT2(120, "评论通知2",MessageTypeEnum.COMMENT.name());


    private Integer code;
    private String remark;
    private String name;

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    ChildTypeEnum(Integer code, String remark, String name) {
        this.code = code;
        this.remark = remark;
        this.name = name;
    }

    public static ItemEum getChildItemEum(Integer code){
        ItemEum itemEum  = new ItemEum();
        Arrays.stream(ChildTypeEnum.values()).forEach(i->{
            if(i.getCode().equals(code)){
                itemEum.setRemark(i.getRemark());
                itemEum.setName(i.getName());
                itemEum.setCode(i.getCode());
            }
        });
        return itemEum;
    }
    public static List<ItemEum> getChildTypeEnumList() {
          final List<ItemEum> li = new ArrayList<>();
          Arrays.stream(ChildTypeEnum.values()).forEach(s->{
            if(MessageTypeEnum.getMessageTyFlagByName(s.getName())){
              // 获取一级权益
                if(!li.stream().anyMatch(an->an.getName().equals(s.getName()))){
                    li.add(MessageTypeEnum.getItemEumByName(s.getName()));
                }
                //组装二级权益
                li.stream().forEach(l->{
                    if(l.getName().equals(s.getName())){
                       l.getCh().add(getChildItemEum(s.getCode()));
                    }
                });
            }
        });
        return li.stream().sorted(Comparator.comparing(ItemEum::getCode)).collect(Collectors.toList());
    }

}
